Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jun 25, 2025

This PR extends the jekyll-optional-front-matter plugin to support Jekyll collections, addressing the limitation that it previously only worked with regular pages.

Problem

The plugin only processed markdown files in the site root as pages, but didn't handle collection documents (files in _posts/, _articles/, etc.) that lacked front matter. Users wanting to use the plugin with collections had to manually add front matter to every collection document.

Solution

Extended the generator to:

  • Detect markdown files in collection directories that lack front matter
  • Convert these static files into proper Jekyll::Document objects
  • Add them to their respective collections with content pre-converted to HTML
  • Optionally remove the original static files when remove_originals is enabled

Key Changes

  • Enhanced generator logic: Now processes both pages and collection documents
  • New collection detection: Identifies collection directories and validates against site configuration
  • Document creation: Converts static files to Jekyll::Document objects with proper content loading
  • Blacklist compatibility: Extended filename blacklist to work with both pages and documents
  • Content conversion: Pre-converts Markdown to HTML for collection documents
  • Static file cleanup: Properly handles removal of original collection files

Example Usage

# _config.yml
collections:
  articles:
    output: true
    permalink: /:collection/:name/

optional_front_matter:
  remove_originals: true
<!-- _articles/my-article.md (no front matter needed) -->
# My Article

This will now be processed as a collection document.

Testing

Added comprehensive tests covering:

  • Collection document detection and processing
  • Integration with existing page functionality
  • Static file removal for collections
  • Blacklist functionality for collection documents
  • Multiple collection types (posts, custom collections)

All existing tests continue to pass, ensuring backward compatibility.

Fixes #41.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] Does it apply to collections? Add support for Jekyll collections to jekyll-optional-front-matter Jun 25, 2025
Copilot AI requested a review from benbalter June 25, 2025 19:31
Copilot finished work on behalf of benbalter June 25, 2025 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Does it apply to collections?

2 participants